﻿App.UserController = Ember.ObjectController.extend({
    actions: {
        editUser: function () {
            var model = this.get('model');
            model.set('DateState', DataStateEnum.Editing);
            model.set('_IsEditing', true);
        },
        lookUser: function () {
            var model = this.get('model');
            this.transitionToRoute('users.detail', model.get('id'));
        },
        saveUser: function () {
            var model = this.get('model');
            model.set('DateState', DataStateEnum.Changed);
            model.set('_IsEditing', false);
            model.save();
        },
        deleteUser: function () {
            var model = this.get('model');
            model.deleteRecord();
            model.save();
        }
    }
});


App.UsersController = Ember.ArrayController.extend({
    sortProperties: ['id'],
    sortAscending: true, // false for descending
    actions: {
        createUser: function () {
            var user = this.store.createRecord('user');
            user.set('_IsEditing', true);
        },
        search: function () {
            var where = $('#search').val();
            if (where) {
                this.transitionToRoute('users.search', $.param({
                    UserName: $('#search').val()
                }));
            } else {
                this.transitionToRoute('users');
            }
        }
    }
});
App.PageModel = DS.Model.extend({ num: DS.attr('number') });
App.PageController = Ember.ObjectController.extend({
    actions: {
        
    }
});

var DataStateEnum = {
    None: 1,
    New: 0,
    Deleted: 2,
    Editing: 3,
    Changed: 4
}